<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use DB;
use Hash;
session_start();

class CommonController extends Controller
{
    //显示登录界面
    public function login()
    {
    	return view('admin.login');

    }

    // 用户登录检测

    public function dologin(Request $request)
    {
    	
    	$name = $request->input('username');
    
    	// 读取表中的用户信息
    	$res = DB::table('shop_users')->where('username',$name)->first();
    
    	if(!$res){

    		return back();
    	}else{
    		// dd($res->password);
    		// 检测密码
    		if(Hash::check($request->input('password'),$res->password)){
    		     session(['id'=>$res->id]);
    		     // dd(session('id'));
    			return redirect('/admin');
    		}else{
    			return back();
    		}
    	}
    	
    }
}
